# Reference:
# https://github.com/cvpaperchallenge/Ascender
# https://github.com/nerfstudio-project/nerfstudio

# FROM nvidia/cuda:11.8.0-devel-ubuntu22.04
FROM registry.aibee.cn/aibee/cuda-12.1.0-cudnn8-devel-ubuntu20.04:latest


WORKDIR /home
ARG USER_NAME=root
ARG GROUP_NAME=root
ARG UID=1000
ARG GID=1000

# Set compute capability for nerfacc and tiny-cuda-nn
# See https://developer.nvidia.com/cuda-gpus and limit number to speed-up build
# ENV TORCH_CUDA_ARCH_LIST="6.0 6.1 7.0 7.5 8.0 8.6 8.9 9.0+PTX"
# ENV TCNN_CUDA_ARCHITECTURES=90;89;86;80;75;70;61;60
# Speed-up build for RTX 30xx
ENV TORCH_CUDA_ARCH_LIST="8.6"
ENV TCNN_CUDA_ARCHITECTURES=86
# Speed-up build for RTX 40xx
# ENV TORCH_CUDA_ARCH_LIST="8.9"
# ENV TCNN_CUDA_ARCHITECTURES=89

ENV CUDA_HOME=/usr/local/cuda
ENV PATH=${CUDA_HOME}/bin:/${USER_NAME}/.local/bin:${PATH}
ENV LD_LIBRARY_PATH=${CUDA_HOME}/lib64:${LD_LIBRARY_PATH}
ENV LIBRARY_PATH=${CUDA_HOME}/lib64/stubs:${LIBRARY_PATH}

RUN   apt-get update && apt-get install -y  unzip && apt-get install -y git 


# apt install by root user
#!+===============================================================================================================================================
# RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
#     build-essential \
#     curl \
#     git \
#     libegl1-mesa-dev \
#     libgl1-mesa-dev \
#     libgles2-mesa-dev \
#     libglib2.0-0 \
#     libsm6 \
#     libxext6 \
#     libxrender1 \
#     python-is-python3 \
#     python3.10-dev \
#     python3-pip \
#     wget \
#     && rm -rf /var/lib/apt/lists/*

#!+===============================================================================================================================================



RUN pip config set global.index-url https://mirrors.aliyun.com/pypi/simple/

RUN pip install --upgrade pip setuptools ninja
#!+===============================================================================================================================================
# RUN pip install torch==2.0.1+cu118 torchvision==0.15.2+cu118 --index-url https://download.pytorch.org/whl/cu118
#!+===============================================================================================================================================
# Install nerfacc and tiny-cuda-nn before installing requirements.txt
# because these two installations are time consuming and error prone



# RUN pip install git+https://github.com/KAIR-BAIR/nerfacc.git@v0.5.2
# WORKDIR /home/${USER_NAME}
# COPY nerfacc-master.zip /home/${USER_NAME}/nerfacc-master.zip
# RUN unzip nerfacc-master.zip
# WORKDIR /home/${USER_NAME}/nerfacc-master
# RUN pip install .



# RUN pip install git+https://github.com/NVlabs/tiny-cuda-nn.git#subdirectory=bindings/torch

#* pip install . 无法安装但是python setup.py install 可以
COPY tiny-cuda-nn ./tiny-cuda-nn
RUN cd tiny-cuda-nn/bindings/torch && python3 setup.py install

RUN pip install  git+https://github.com/kornia/kornia.git

COPY requirements.txt /tmp/requirements.txt
RUN cd /tmp && pip install -r requirements.txt









#*  one more thing 
RUN pip install rembg && pip install envlight

#* reference: https://nvlabs.github.io/nvdiffrast/#linux
RUN git clone https://github.com/NVlabs/nvdiffrast
RUN cd nvdiffrast && pip install .
RUN pip install nerfacc




RUN pip install ftfy regex tqdm
RUN pip install git+https://github.com/openai/CLIP.git


RUN pip install open3d &&  pip install mmcv-full && \
pip install nuscenes-devkit && pip install segment_anything


WORKDIR  /root/exp




